import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class project {
    public List<Integer> pathInZigZagTree(int label) {
        List<Integer> list=get(label);
        boolean bool=false;
        for(int i=list.size()-1;i>=0;i--){
            if(bool){
                int num=reverse(i,list.get(i));
                list.set(i,num);
            }
            bool=!bool;
        }
        return list;
    }
    public int reverse(int i,int j){
        return (1<<i)+(1<<i+1)-1-j;
    }
    public List<Integer> get(int label){
        LinkedList<Integer> list=new LinkedList<>();
        while (label>0){
            list.addFirst(label);
            label/=2;
        }
        return list;
    }
}
